package net.pimpas.core.monitor;

public final class DefaultMonitor {
	
	private volatile boolean locked;
	private Object object;
	
	public DefaultMonitor() {
		this.setLocked(false);
		this.setObject(new Object());
	}
	
	public synchronized void doLock( ) {
		if(this.isLocked()) return;
		
		this.setLocked(true);
	}
	
	public synchronized void unLock( ) {
		if(!this.isLocked()) return;
		
		this.setLocked(false);
		notifyAll();
	}
	
	public synchronized void waitUnlock( ) {
		while(this.isLocked())
			try {
				wait( );
			} catch (InterruptedException e) {
			}
	}

	public boolean isLocked() {
		return locked;
	}

	public void setLocked(boolean locked) {
		this.locked = locked;
	}


	public Object getObject() {
		return object;
	}


	public void setObject(Object object) {
		this.object = object;
	}
}